Miscellaneous
Comments
Comments in Salsa are the same as C. Specifically, the text "/*" begins the comment, and it ends after the text "*/". You cannot nest comments, therefore:
a = /* comment 1 /* nested comment */ back to 1 */ 6;
will not work because the "*/" after "comment" closes the entire comment.
Unconditional Jumping
Sometimes you will want a program to jump from one place to another. With old programming languages such as BASIC, you could specify line numbers for each line, and then instruct the computer to go to a particular line. Since there are no line numbers, you must create labels for any code which you would like to jump to. Labels are written as in C: simply give the label any name and then put a colon. Then the goto operator can be used to jump to that code from anywhere else in that function. For example, the following code will take user input and display wether the input was 0 or not:
def main()
{
x = input();
if (x)
goto NOT_ZERO;
println("x is zero!");
goto DONE;
NOT_ZERO: println("x is not zero!");
DONE:
}
As you can see, a label does not have to preceed a command; the last simply refers to the end of main(). In general, it is better to use if-then-else, looping structures, and function calls instead of labels since they are easier to read, and the code is easier to debug.
Web page maintained by Jason Cohen